<?php

declare (strict_types=1);

namespace App\Application\Admin\Model;
use Hyperf\Database\Model\SoftDeletes;
use Hyperf\DbConnection\Db;
use Hyperf\DbConnection\Model\Model;

/**
 * @property int $goods_type_id
 * @property string $name
 * @property string $deleted_at
 */
class Goodstype extends Model
{
    use SoftDeletes;

    protected string $primaryKey = 'goods_type_id';
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected ?string $table = 'goods_type';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected array $fillable = ['goods_type_id', 'name'];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected array $casts = [
        'goods_type_id' => 'integer',
        'name' => 'string',
        'created_at' => 'datetime',
        'updated_at' => 'datetime'
    ];


    /**
     * 创建标签
     *
     * @return bool
     * @throws ErrorException
     */
    static function createStore(int $goods_type_id, array $label = []): self
    {
        Db::beginTransaction();
        $label = self::updateOrCreate(['goods_type_id' => $goods_type_id], $label);
        Db::commit();
        return $label;

    }

}